
#include "drawspart_spider.h"
#include "drawspart_moku.h"
#include "draw_table.h"

/**
 * fungsi penggambar ruangan, dengan menggambar satu-satu komponen dari ruangan.
 * dimulai dari lantai dan dilanjutkan pada tembok-temboknya.
 */
void drawPlane(void) {
    // draw floor
    glColor3f(0.6, 0.6, 0.9);
    glBegin(GL_POLYGON);
        glVertex3f(-30.0, -10.0, -30);
        glVertex3f(-30.0, -10.0, 20);
        glVertex3f(50.0, -10.0, 20);
        glVertex3f(50.0, -10.0, -30);
    glEnd();

    // draw left wall
    glColor3f(0.0, 0.5, 0.65);
    glBegin(GL_POLYGON);
        glVertex3f(-30, -10, -30);
        glVertex3f(-30, -10, 20);
        glVertex3f(-30, 17, 20);
        glVertex3f(-30, 17, -30);
    glEnd();

    // draw right wall
    glColor3f(0.0, 0.5, 0.65);
    glBegin(GL_POLYGON);
        glVertex3f(50, -10, -30);
        glVertex3f(50, -10, 20);
        glVertex3f(50, 17, 20);
        glVertex3f(50, 17, -30);
    glEnd();

    // draw back wall
    glColor3f(0.0, 0.7, 0.9);
    glBegin(GL_POLYGON);
        glVertex3f(-30, -10, -30);
        glVertex3f(-30, 17, -30);
        glVertex3f(50, 17, -30);
        glVertex3f(50, -10, -30);
    glEnd();

    // draw ceiling
    glColor3f(0.2, 0.2, 0.2);
    glBegin(GL_POLYGON);
        glVertex3f(-30, 17, -30);
        glVertex3f(-30, 17, 20);
        glVertex3f(50, 17, 20);
        glVertex3f(50, 17, -30);
    glEnd();
}

static void renderEnviroment() {
    glPushMatrix();
    drawPlane();  // menggambar ruangan
    glPopMatrix();

    // membuat lampu bergerak
    glPushMatrix(); // light source dynamic
        updRotationAngle();
        if (isLight[0]) glColor3f(1.0, 0.0, 0.0);
        else glColor3f(0.0, 0.0, 0.0);

        GLfloat tempLampPos [] = {lamp1_pos[0],lamp1_pos[1],lamp1_pos[2],1.0};

        glTranslatef(0.0, 0.0, 0.0);
        glLightfv(GL_LIGHT5, GL_POSITION, tempLampPos);
        glTranslatef(lamp1_pos[0], lamp1_pos[1], lamp1_pos[2]);
        glutSolidSphere(0.3, 10, 10); // menggambar lampu merah
    glPopMatrix();

    // membuat lampu putih
    glPushMatrix();
		if (isLight[1]) {
			glColor3f(1.0, 1.0, 1.0);
		} else {
			glColor3f(0.0, 0.0, 0.0);
		}
		glLightfv(GL_LIGHT0, GL_POSITION, light_position);
		glTranslatef(0.0, 16.0, 19.0);
		glutSolidSphere(0.3, 10, 10);
    glPopMatrix();

    // membuat lampu hijau
    glPushMatrix();
		if (isLight[2]) {
			glColor3f(0.0, 1.0, 0.0);
		} else {
			glColor3f(0.0, 0.0, 0.0);
		}
		glLightfv(GL_LIGHT1, GL_POSITION, lamp_one_position);
		glTranslatef(-29, 16, 0.0);
		glutSolidSphere(0.3, 10, 10);
    glPopMatrix();

    // membuat lampu biru
    glPushMatrix();
		if (isLight[3]) {
			glColor3f(0.0, 0.0, 1.0);
		} else {
			glColor3f(0.0, 0.0, 0.0);
		}
		glLightfv(GL_LIGHT2, GL_POSITION, lamp_two_position);
		glTranslatef(49, 16, 0.0);
		glutSolidSphere(0.3, 10, 10);
    glPopMatrix();
}
